package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.constant.RedisMessageConstant;
import com.itheima.utils.SMSUtils;
import com.itheima.utils.ValidateCodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import redis.clients.jedis.JedisPool;
import service.ValidateCodeService;

@Transactional
@Service(interfaceClass = ValidateCodeService.class)
public class ValidateCodeServiceImpl implements ValidateCodeService {
    @Autowired
    private JedisPool jedisPool;

    /**
     * 套餐预约发送验证码
     * @param
     * @return
     */
    @Override
    public void send4Order(String telephone) {
        Integer code = ValidateCodeUtils.generateValidateCode(4);
        SMSUtils.sendShortMessage("SMS_173475910",telephone , code+"");
        //存到redis 并设定过期时间
        jedisPool.getResource().setex(telephone+ RedisMessageConstant.SENDTYPE_ORDER, 60*60, code+"");

    }

    /**
     * 用于手机快速登录
     * 短信登录发送验证码
     * @param
     * @return
     */
    @Override
    public void send4Login(String telephone) {
        Integer code = ValidateCodeUtils.generateValidateCode(4);
        SMSUtils.sendShortMessage("SMS_173475910",telephone , code+"");
        //存到redis 并设定过期时间
        jedisPool.getResource().setex(telephone+RedisMessageConstant.SENDTYPE_LOGIN, 60*60, code+"");
    }
}
